package com.zoweunion.mechanic.controller.shangji;

import cn.jpush.api.push.PushResult;
import com.alibaba.fastjson.JSONObject;
import com.zoweunion.mechanic.controller.BaseController;
import com.zoweunion.mechanic.dao.app.AppDao;
import com.zoweunion.mechanic.dao.base.MessageRecordDao;
import com.zoweunion.mechanic.dao.shangji.ShangJiDao;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.model.User;
import com.zoweunion.mechanic.model.app.ReportViolations;
import com.zoweunion.mechanic.plugins.shiro.JWTUtil;
import com.zoweunion.mechanic.service.app.PersonalCenterService;
import com.zoweunion.mechanic.service.base.MessageRecordService;
import com.zoweunion.mechanic.service.base.UserService;
import com.zoweunion.mechanic.service.shangji.ShangJiService;
import com.zoweunion.mechanic.util.JiGuangPushUtil;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.util.UuidUtil;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.constants.PushConstants;
import com.zoweunion.mechanic.util.upload.UploadFile;
import com.zoweunion.mechanic.util.upload.UploadResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

@SuppressWarnings("unchecked")
@RestController
@RequestMapping("/shangji")
public class ShangJiController extends BaseController {

	@Autowired
	private ShangJiService shangJiService;
	@Autowired
	private MessageRecordService messageRecordService;
	@Autowired
	private UserService userService;
	@Autowired
	private PersonalCenterService personalCenterService;
	@Autowired
	private JiGuangPushUtil jiGuangPushUtil;
	@Autowired
	private MessageRecordDao messageRecordDao;
	@Autowired
	private ShangJiDao shangJiDao;
	@Autowired
	private AppDao appDao;

	/**
	 * 推荐列表
	 * @param
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/reportViolations")
	public ResponseBean listRecommend(@RequestBody ReportViolations reportViolations, HttpServletRequest request) throws Exception {
		logBefore(logger, "推荐列表");
		String authorization = request.getHeader("Authorization");
		String userAccount = JWTUtil.getUsername(authorization);
		User currentUser = userService.getUserByAccount(userAccount);
		reportViolations.setReportUser(currentUser.getId());
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功", shangJiService.insertReportViolations(reportViolations));
	}

	/**
	 * 推荐列表
	 * @param
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listRecommend")
	public ResponseBean listRecommend(@RequestBody String str, HttpServletRequest request) throws Exception {
		logBefore(logger, "推荐列表");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		List<Map<String, Object>> brandList = shangJiService.listRecommend(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功", brandList);
	}

	/**
	 * 获取品牌列表
	 * @param
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listBrand")
	public ResponseBean listBrand(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取品牌列表");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		List<Map<String, Object>> brandList = shangJiService.listBrand(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功", brandList);
	}
	/**
	 * 获取品牌列表
	 * @param
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listBrandClassify")
	public ResponseBean listBrandClassify(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取品牌列表");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		Map<String, Object> brand = shangJiService.listBrandClassify(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功", brand);
	}

	/**
	 * 修改电话咨询
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/updateTelConsult")
	public ResponseBean updateTelConsult(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "修改电话咨询");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		int result = shangJiService.updateTelConsult(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取服务商banner图列表
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getBannerPicPath")
	public ResponseBean getBannerPicPath(HttpServletRequest request) throws MyException, IOException {
		logBefore(logger, "获取服务商banner图列表");
		User user = getCurrentUser(request);
		Map<String, Object> resMap = shangJiService.getBannerPicPathList(user);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resMap);
	}
	/**
	 * 获取轮播图
	 * @param request
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getBannerPic")
	public ResponseBean getBannerPic(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取服务商banner图列表");
		User user = getCurrentUserNoVerify(request);
		Map<String, Object> resMap = shangJiService.getBannerPic(user);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resMap);
	}


	/**
	 * 保存分享奖品的接受人
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/savePrizeRecipient")
	public ResponseBean savePrizeRecipient(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "保存分享奖品的接受人");
        Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		String userId = getCurrentUser(request).getId();
        reqMap.put("user_id", userId);
		Map<String, Object> data = shangJiService.savePrizeRecipient(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 获取分享的奖品记录
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listSharePrizeSelf")
	public ResponseBean listSharePrizeSelf(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取最新10条分享得到的奖品");
		String userId = getCurrentUser(request).getId();
		List<Map<String, Object>> data = shangJiService.listSharePrizeSelf(userId);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 我邀请的人列表
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyInvitePeopleList")
	public ResponseBean getMyInvitePeopleList(HttpServletRequest request) throws MyException {
		logBefore(logger, "我邀请的人列表");
		User currentUser = getCurrentUser(request);
		List<Map<String, Object>> data = shangJiService.listMyInvitePeople(currentUser);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 获取最新10条分享得到的奖品
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listSharePrizeLastTenData")
	public ResponseBean listSharePrizeLastTenData(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取最新10条分享得到的奖品");
		List<Map<String, Object>> data = shangJiService.listSharePrizeLastTenData();
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 获取最新10条分享得到的流量(虚拟数据)
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listShareAppLastTenData")
	public ResponseBean listShareAppLastTenData(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取最新10条分享得到的流量");
		List<Map<String, Object>> data = shangJiService.listShareAppLastTenData();
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 获取分享邀请码
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getShareInvitationCode")
	public ResponseBean getShareInvitationCode(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取分享邀请码");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> data = shangJiService.getShareInvitationCode(userId);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}
	/**
	 * 使用邀请码
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/useShareInvitationCode")
	public ResponseBean useShareInvitationCode(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "使用分享邀请码");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		User user = getCurrentUser(request);
		reqMap.put("user_id", user.getId());
		Map<String, Object> data = shangJiService.useShareInvitationCode(user, reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 签到数据，返回连续签到次数和剩余抽奖次数
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getActivitySignIn")
	public ResponseBean getActivitySignIn(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取签到信息");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> data = shangJiService.getActivitySignInByUserId(userId);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", data);
	}

	/**
	 * 签到活动的每天签到
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/activitySignIn")
	public ResponseBean activitySignIn(HttpServletRequest request) throws MyException {
		logBefore(logger, "活动签到");
		User currentUser = getCurrentUser(request);
		Map<String, Object> reqMap = new HashMap<>();
		reqMap.put("user_id", currentUser.getId());
		Map<String, Object> responseMap = shangJiService.activitySignIn(currentUser, reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", responseMap);
	}

	/**
	 * 签到活动的抽奖
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/activitySignInPrize")
	public ResponseBean activitySignInPrize(HttpServletRequest request) throws MyException {
		logBefore(logger, "开始抽奖");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = new HashMap<>(2);
		reqMap.put("user_id", userId);
		Map<String, Object> responseMap = shangJiService.activitySignInPrize(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", responseMap);
	}
	/**
	 * 保存抽奖奖品的领取信息
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/saveActivitySignInPrize")
	public ResponseBean saveActivitySignInPrize(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "保存抽奖奖品");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("user_id", userId);
		Map<String, Object> responseMap = shangJiService.saveActivitySignInPrize(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", responseMap);
	}
	/**
	 * 保存抽奖奖品的领取信息
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/saveActivitySignInPrizeNew")
	public ResponseBean saveActivitySignInPrizeNew(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "保存抽奖奖品");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("user_id", userId);
		Map<String, Object> responseMap = shangJiService.saveActivitySignInPrizeNew(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", responseMap);
	}
	/**
	 * 获取抽奖奖品列表
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/listPrize")
	public ResponseBean saveActivitySignInPrize(@RequestBody String str) throws MyException {
		logBefore(logger, "保存抽奖奖品");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		List<Map<String, Object>> responseMap = shangJiService.listPrize(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", responseMap);
	}

	/**
	 * 删除我的发布
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/deleteMyRelease")
	public ResponseBean deleteMyRelease(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "删除我的发布");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		reqMap.put("r_id",getCurrentUser(request).getR_id());
		int result = shangJiService.deleteMyRelease(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", result);
	}

	/**
	 * 获取我的发布 分类别的全部id
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyReleaseId")
	public ResponseBean getMyReleaseId(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取我的发布的全部id");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getMyReleaseId(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 我的发布搜索
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/myReleaseSearch")
	public ResponseBean myReleaseSearch(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "我的发布搜索");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.myReleaseSearch(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}



	/**
	 * 获取我的发布
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyRelease")
	public ResponseBean getMyRelease(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取我的发布");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		reqMap.put("s_id",getCurrentUser(request).getS_id());
		reqMap.put("r_id",getCurrentUser(request).getR_id());
		Map<String, Object> resultMap = shangJiService.getMyReleaseNew(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 获取我的发布
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyReleaseNew")
	public ResponseBean getMyReleaseNew(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取我的发布");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getMyReleaseNew(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 获取热门城市
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getHotCity")
	public ResponseBean getHotCity() throws MyException {
		logBefore(logger, "获取热门城市");
		Map<String, Object> resultMap = shangJiService.getHotCity();
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 获取最近访问城市
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getRecentVisitCity")
	public ResponseBean getRecentVisitCity(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取最近访问城市");
		Map<String, Object> reqMap = new HashMap<>();
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getRecentVisitCity(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 修改最近访问城市
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/updateRecentVisitCity")
	public ResponseBean updateRecentVisitCity(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "修改最近访问城市");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		User user = getCurrentUser(request);
		reqMap.put("u_id", user.getId());
		reqMap.put("u_name", user.getUser_name());
		int result = shangJiService.updateRecentVisitCity(reqMap);
		if (result == 1) {
			return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
		} else {
			return new ResponseBean(Constants.CODE_ERROR,"操作失败",result);
		}
	}

	/**
	 * 获取分类名称
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getTypeConfigure")
	public ResponseBean getTypeConfigure(@RequestBody String str) throws MyException {
		logBefore(logger, "获取分类名称");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		Map<String, Object> resultMap = shangJiService.getTypeConfigure(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 新增分类名称
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/insertTypeConfigure")
	public ResponseBean insertTypeConfigure(@RequestBody String str) throws MyException {
		logBefore(logger, "新增分类名称");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		int result = shangJiService.insertTypeConfigure(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 删除我的收藏搜索记录
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/delMycollectionSearchRecord")
	public ResponseBean delMycollectionSearchRecord(@RequestBody  String str, HttpServletRequest request) throws MyException {
		logBefore(logger,"删除我的收藏搜索记录");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		int result = shangJiService.delMycollectionSearchRecord(reqMap);
		logAfter(logger);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取我的收藏搜索记录
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMycollectionSearchRecord")
	public ResponseBean getMycollectionSearchRecord(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger,"获取我的收藏搜索记录");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getMycollectionSearchRecord(reqMap);
		logAfter(logger);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 新增我的收藏搜索记录
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/addMycollectionSearchRecord")
	public ResponseBean addMycollectionSearchRecord(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger,"新增我的收藏搜索记录");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		if (StringUtils.isBlank(reqMap.get("name").toString())) {
			throw new MyException(Constants.CODE_HANDEL_FAILED, "标题不能为空");
		}
		User user = getCurrentUser(request);
		reqMap.put("u_id", user.getId());
		reqMap.put("u_name", user.getUser_name());
		int result = shangJiService.addMycollectionSearchRecord(reqMap);
		logAfter(logger);
		if (result == 0) {
			return new ResponseBean(Constants.CODE_HANDEL_FAILED, "新增失败", result);
		}
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取我的收藏 分类别的全部id
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyCollectionId")
	public ResponseBean getMyCollectionId(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取我的收藏的全部id");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getMyCollectionId(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 我的收藏搜索
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/myCollectionSearch")
	public ResponseBean myCollectionSearch(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "我的收藏搜索");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.myCollectionSearch(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 获取单个我的收藏
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyCollection")
	public ResponseBean getMyCollection(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取单个我的收藏");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getMyCollection(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 我的收藏类型
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMyCollectionType")
	public ResponseBean getMyCollectionType(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "我的收藏类型");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		List<Map<String, Object>> resultMap = shangJiService.getMyCollectionType(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 分类别获取我的收藏
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getTypeMyCollection")
	public ResponseBean getTypeMyCollection(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "分类别获取我的收藏");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		Map<String, Object> resultMap = shangJiService.getTypeMyCollection(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 删除我的收藏
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/deleteMyCollection")
	public ResponseBean deleteMyCollection(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "删除我的收藏");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("u_id", getCurrentUser(request).getId());
		int result = shangJiService.deleteMyCollection(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 新增我的收藏
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/insertMyCollection")
	public ResponseBean insertMyCollection(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "新增我的收藏");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		User currentUser = getCurrentUser(request);
		String device = getDevice(request);
		reqMap.put("u_id", currentUser.getId());
		reqMap.put("u_name", currentUser.getUser_name());
		reqMap.put("mobile_phone",currentUser.getMobile_phone());
		Map<String, Object> result = shangJiService.insertMyCollection(currentUser, reqMap,device);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 新增询底价
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/insertInquiry")
	public ResponseBean insertInquiry(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "新增询底价");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		if ((reqMap.get("b_id") == null || "".equals(reqMap.get("b_id"))) ||
				(reqMap.get("name") == null || "".equals(reqMap.get("name")))) {
			return new ResponseBean(Constants.CODE_ERROR,"操作失败",null);
		}
		if (!reqMap.get("phone").toString().matches("^1\\d{10}$") || reqMap.get("phone").toString().length() != 11) {
			return new ResponseBean(Constants.CODE_ERROR,"手机号验证失败",null);
		}
		try {
			reqMap.put("c_id", getCurrentUser(request).getId());
			reqMap.put("user_name", getCurrentUser(request).getUser_name());
		} catch (Exception e) {
			reqMap.put("c_id", "");
			reqMap.put("user_name", "");
		}
		int result = shangJiService.insertInquiry(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取询底价信息
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getInquiryInfo")
	public ResponseBean getInquiryInfo(@RequestBody String str) throws MyException {
		logBefore(logger, "获取询底价信息");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		if (reqMap.get("b_id") == null || "".equals(reqMap.get("b_id"))) {
			return new ResponseBean(Constants.CODE_ERROR,"操作失败",null);
		}
		Map<String, Object> resultMap = shangJiService.getInquiryInfo(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	/**
	 * 找设备--获取机械设备
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMechanics")
	public ResponseBean getMechanics(@RequestBody String str) throws MyException {
		logBefore(logger, "获取机械设备");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		Map<String, Object> resultMap = shangJiService.getMechanics(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}
	/**
	 * 出租、出售获取品牌、属性
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getBrandAttribute")
	public ResponseBean getBrandAttribute(@RequestBody String str) throws MyException {
		logBefore(logger,"出租、出售获取品牌属性");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		Map<String, Object> result = shangJiService.getBrandAttribute(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取出租、出售机械类别
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getSaleMechanicsType")
	public ResponseBean getSaleMechanicsType(@RequestBody String str) throws MyException {
		logBefore(logger,"获取出租、出售机械类别");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		List<Map<String, Object>> result = shangJiService.getSaleMechanicsType(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取出租、出售机械类别
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getSaleMechanicsTypeClassify")
	public ResponseBean getSaleMechanicsTypeClassify(@RequestBody String str) throws MyException {
		logBefore(logger,"获取出租、出售机械类别 分类");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		Map<String, Object> result = shangJiService.getSaleMechanicsTypeClassify(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}
	/**
	 * 获取机械类别
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getMechanicsType")
	public ResponseBean getMechanicsType() throws MyException {
		logBefore(logger,"获取机械类别");
		List<Map<String, Object>> result = shangJiService.getMechanicsType();
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	/**
	 * 获取机械类别下的小类别、品牌、属性
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/getTypeBrandAttribute")
	public ResponseBean getTypeBrandAttribute(@RequestBody String str) throws MyException {
		logBefore(logger,"获取小类别、品牌、属性");
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		Map<String, Object> result = shangJiService.getTypeBrandAttribute(reqMap);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}

	@PostMapping("/getUserInfo")
	public Object getUserInfo(HttpServletRequest request) throws MyException {
		logBefore(logger, "获取用户信息");
		Map<String, Object> result = new HashMap<>();
		JSONObject resultObj = new JSONObject();
		try {
			result.put("user",userService.getUserInfoByAccount(getCurrentUser(request).getUser_account()));
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}
		return resultObj;
	}

	/**
	 * 获取消息数量根据用户
	 * @throws MyException
	 */
	@PostMapping("/recordNumberByReceiveUser")
	public ResponseBean recordNumberByReceiveUser(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "消息推送记录_消息数量据用户");
		Map<String,Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("s_id", getCurrentUser(request).getS_id());
		reqMap.put("receive_user", getCurrentUser(request).getId());
		Map<String, Object> resultMap=messageRecordService.recordNumberByReceiveUser(reqMap);
		logAfter(logger);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",resultMap);
	}

	//店铺发布
	@PostMapping("/publishShop")
	public Object publishShop(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "商机发布");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		JSONObject resultObj=new JSONObject();
		User user = getCurrentUser(request);
		map.put("create_user", user.getId());
		map.put("update_user", user.getId());
		if(map.get("id")!=null && !map.get("id").toString().equals("")){
			int result = shangJiService.updateShop(map,user);
			if(result>0){
				Map<String, Object> resultMap = new HashMap<>();
				resultMap.put("id",map.get("id").toString());
				resultMap.put("result",result);
				resultObj.put("data", resultMap);
				resultObj.put("code", Constants.CODE_SUCCESS);
				resultObj.put("message", "编辑成功");
			}else{
				resultObj.put("code", Constants.CODE_HANDEL_FAILED);
				resultObj.put("message", "编辑失败");
			}

		}else{
			Map<String, Object> resultMap = shangJiService.publish(user, map);
			resultObj.put("data", resultMap);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		}
		return resultObj;
	}

//	//店铺图片上传
//	@PostMapping("/UploadPhoto")
//	public Object uploadPhoto(@RequestBody String str,@RequestParam("file") MultipartFile file) throws MyException{
//		logBefore(logger, "图片上传");
//		if (file == null) {
//			throw new MyException(Constants.CODE_HANDEL_FAILED, "对象不能为空");
//		}
//		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
//		shangJiService.uploadPhoto(file);
//		return new Object(Constants.CODE_SUCCESS,"操作成功",null);
//	}

	//店铺列表获取
	@PostMapping("/getShopList")
	public Object getShopList(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "商机店铺列表获取");
        User currentUser = getCurrentUserNoVerify(request);
        String device = getDevice(request);
		Map<String, Object> reqMap = JSONObject.parseObject(str,Map.class);
		try {
			reqMap.put("u_id", getCurrentUser(request).getId());
		} catch (Exception e) {
			reqMap.put("u_id", request.getSession().getId());
		}
		List<Map<String, Object>> resultlist;
		JSONObject resultObj=new JSONObject();
		try {
			resultlist = shangJiService.getShopList(reqMap,currentUser,device);
			// 为防止app端更改代码做的勉强操作
			if(reqMap.get("examine_flag") != null){
				resultObj.put("total", shangJiService.getShopListCount(reqMap));
			}
			resultObj.put("data", resultlist);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {
            e.printStackTrace();
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//店铺列表获取
	@PostMapping("/getShopListNew")
	public ResponseBean getShopListNew(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "维修店铺列表获取");
		Map<String, Object> reqMap = JSONObject.parseObject(str,Map.class);
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		try {
			reqMap.put("u_id", getCurrentUser(request).getId());
		} catch (Exception e) {
			reqMap.put("u_id", request.getSession().getId());
		}
		List<Map<String, Object>> resultlist;
		resultlist = shangJiService.getShopListNew(reqMap,currentUser,device);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultlist);
	}

	/**
	 * 审核店铺
	 * @param str
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/checkShop")
	public Object checkShop(@RequestBody String str, HttpServletRequest request) throws Exception {
		logBefore(logger, "审核商机店铺");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("update_user", userId);
		boolean status = shangJiService.updateShopExamineFlag(reqMap);
		Map<String, Object> resultObj = new HashMap<>(2);
		resultObj.put("status", status);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultObj);
	}

	//获取商机店铺详情
	@PostMapping("/getShopInfo")
	public Object getShopInfo(@RequestBody String str,HttpServletRequest request) throws MyException {
		logBefore(logger, "获取商机店铺详情");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		Map<String, Object> resultlist;
		JSONObject resultObj=new JSONObject();
		try {
			User currentUser = getCurrentUserNoVerify(request);
			String device = getDevice(request);
			resultlist = shangJiService.getShopInfo(map,currentUser,device);
			resultObj.put("data", resultlist);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//中标列表页面
	@GetMapping("/getzhongbiaoList")
	public Object getzhongbiaoList(@RequestParam Map<String,Object> map,HttpServletRequest request) throws Exception {
		logBefore(logger, "中标列表页面");
        User currentUser = getCurrentUserNoVerify(request);
        String device = getDevice(request);
//		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		List<Map<String, Object>> resultlist;
		JSONObject resultObj=new JSONObject();
		resultlist = shangJiService.getzhongbiaoList(map,currentUser,device);
		resultObj.put("data", resultlist);
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		return resultObj;
	}

	//获取招中标详情
	@PostMapping("/getzhongbiaoInfo")
	public Object getzhongbiaoInfo(@RequestBody String str,HttpServletRequest request) throws MyException {
		logBefore(logger, "获取招中标详情");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
        User currentUser = getCurrentUserNoVerify(request);
        String device = getDevice(request);
		List<Map<String, Object>> result;
		JSONObject resultObj=new JSONObject();
		try {
			result = shangJiService.getzhongbiaoInfo(map,currentUser,device);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//发布车辆
	@PostMapping("/publishCars")
	public Object publishCars(@RequestBody String str) throws MyException {
		logBefore(logger, "发布车辆");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		JSONObject resultObj = new JSONObject();
		try {

			shangJiService.publishCars(map);
			resultObj.put("data", null);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//获取发布的车辆信息列表页面
	@PostMapping("/getpublishCarsList")
	public Object getpublishCarsList(@RequestBody String str) throws MyException {
		logBefore(logger, "获取发布的车辆信息列表页面");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		List<Map<String, Object>> resultlist=null;
		JSONObject resultObj = new JSONObject();
		try {
			resultlist = shangJiService.getpublishCarsList(map);
			resultObj.put("data", resultlist);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}


	//买家发布信息
	@PostMapping("/publishBuyerInfo")
	public Object publishBuyerInfo(@RequestBody String str) throws MyException {
		logBefore(logger, "买家发布信息");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		JSONObject resultObj = new JSONObject();
		try {

			shangJiService.publishBuyerInfo(map);
			resultObj.put("data", null);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//获取买家信息列表页面
	@PostMapping("/getpublishBuyerInfoList")
	public Object getpublishBuyerInfoList(@RequestBody String str) throws MyException {
		logBefore(logger, "获取买家信息列表页面");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		List<Map<String, Object>> resultlist;
		JSONObject resultObj = new JSONObject();
		try {
			resultlist = shangJiService.getpublishBuyerInfoList(map);
			resultObj.put("data", resultlist);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//发布求职信息
	@PostMapping("/publishJoberInfo")
	public Object publishJoberInfo(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "发布求职信息");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		User user = getCurrentUser(request);
		map.put("create_user", user.getId());
		JSONObject resultObj = new JSONObject();
		try {
			//如果有id就是编辑 否则就是发布
           if(map.get("id")!=null && !map.get("id").toString().equals("")){
			   int result = shangJiService.updateJoberInfo(map,user);
			   if(result>0){
				   Map<String, Object> resultMap = new HashMap<>();
				   resultMap.put("id",map.get("id").toString());
				   resultMap.put("result",result);
				   resultObj.put("data", resultMap);
				   resultObj.put("code", Constants.CODE_SUCCESS);
				   resultObj.put("message", "操作成功");
			   }else{
				   resultObj.put("code", Constants.CODE_HANDEL_FAILED);
				   resultObj.put("message", "操作失败");
			   }

		   }else{
			   Map<String, Object> resultMap = shangJiService.publishJoberInfo(user, map);
			   resultObj.put("data", resultMap);
			   resultObj.put("code", Constants.CODE_SUCCESS);
			   resultObj.put("message", "操作成功");
		   }

		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}



	/**
	 * 审核求职信息
	 * @param str
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/checkJober")
	public Object checkJober(@RequestBody String str, HttpServletRequest request) throws Exception {
		logBefore(logger, "审核求职信息");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("update_user", userId);
		boolean status = shangJiService.updateJoberExamineFlag(reqMap);
		Map<String, Object> resultObj = new HashMap<>(2);
		resultObj.put("status", status);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultObj);
	}

	//获取求职者信息列表页面
	@PostMapping("/getJoberInfoList")
	public Object getJoberInfoList(@RequestBody String str,HttpServletRequest request) throws MyException {
		logBefore(logger, "获取求职者信息列表页面");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		Map<String, Object> resultlist;
		JSONObject resultObj = new JSONObject();
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		try {
			resultlist = shangJiService.getJoberInfoList(map,currentUser,device);
			resultObj.put("data", resultlist);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//获取求职者信息页面
	@PostMapping("/getJoberInfo")
	public Object getJoberInfo(@RequestBody String str,HttpServletRequest request) throws Exception {
		logBefore(logger, "获取求职者信息页面");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		Map<String, Object> result=null;
		JSONObject resultObj = new JSONObject();
        result = shangJiService.getJoberInfo(map,currentUser,device);
        resultObj.put("data", result);
        resultObj.put("code", Constants.CODE_SUCCESS);
        resultObj.put("message", "操作成功");
		return resultObj;
	}

	//企业发布招聘信息
	@PostMapping("/publishRecruitInfo")
	public Object publishRecruitInfo(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "发布招聘信息");
		Map<String, Object> reqMap = JSONObject.parseObject(str,Map.class);
		JSONObject resultObj = new JSONObject();
		User user = getCurrentUser(request);
		reqMap.put("u_id", user.getId());
		reqMap.put("create_user", user.getId());
		try {
			//如果有id 就是编辑 没有就是发布
            if(reqMap.get("id")!=null && !reqMap.get("id").toString().equals("")){
				int result = shangJiService.updateRecruitInfo(reqMap,user);
				if(result>0){
					Map<String, Object> resultMap = new HashMap<>();
					resultMap.put("id",reqMap.get("id").toString());
					resultMap.put("result",result);
					resultObj.put("data", resultMap);
					resultObj.put("code", Constants.CODE_SUCCESS);
					resultObj.put("message", "编辑成功");
				}else{
					resultObj.put("code", Constants.CODE_HANDEL_FAILED);
					resultObj.put("message", "编辑失败");
				}
			}else{
				Map<String, Object> resultMap = shangJiService.publishRecruitInfo(user, reqMap);
				resultObj.put("data", resultMap);
				resultObj.put("code", Constants.CODE_SUCCESS);
				resultObj.put("message", "操作成功");
			}

		} catch (Exception e) {
			e.printStackTrace();
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	/**
	 * 审核招聘信息
	 * @param str
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/checkRecruit")
	public Object checkRecruit(@RequestBody String str, HttpServletRequest request) throws Exception {
		logBefore(logger, "审核招聘信息");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("update_user", userId);
		boolean status = shangJiService.updateRecruitExamineFlag(reqMap);
		Map<String, Object> resultObj = new HashMap<>(2);
		resultObj.put("status", status);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultObj);
	}

	//获取招聘信息列表页面
	@PostMapping("/getRecruitInfoList")
	public Object getRecruitInfoList(@RequestBody String str,HttpServletRequest request) throws MyException {
		logBefore(logger, "获取招聘信息列表页面");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		Map<String, Object> resultlist;
		JSONObject resultObj = new JSONObject();
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		try {
			resultlist = shangJiService.getRecruitInfoList(map,currentUser,device);
			resultObj.put("data", resultlist);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	//获取招聘信息页面
	@PostMapping("/getRecruitInfo")
	public Object getRecruitInfo(@RequestBody String str,HttpServletRequest request) throws Exception{
		logBefore(logger, "获取招聘信息详情页面");
        User currentUser = getCurrentUserNoVerify(request);
        String device = getDevice(request);
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		Map<String, Object> result;
		JSONObject resultObj = new JSONObject();
		result = shangJiService.getRecruitInfo(map,currentUser,device);
		resultObj.put("data", result);
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		return resultObj;
	}

	@PostMapping("/getCarType")
	public Object getCarType(@RequestBody String str) throws Exception {
		logBefore(logger, "获取更多车型");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);

		List<Map<String, Object>> result = null;
		JSONObject resultObj = new JSONObject();
		result = shangJiService.getCarType(map);
		resultObj.put("data", result);
		resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		return resultObj;
	}

	@PostMapping("/getCarBrand")
	public Object getCarBrand(@RequestBody String str) throws MyException {
		logBefore(logger, "获取更多车型");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);

		List<Map<String, Object>> result = null;
		JSONObject resultObj = new JSONObject();
		try {
			result = shangJiService.getCarBrand(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	@PostMapping("/getCarModel")
	public Object getCarModel(@RequestBody String str) throws MyException {
		logBefore(logger, "获取更多车型");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);

		List<Map<String, Object>> result = null;
		JSONObject resultObj = new JSONObject();
		try {
			result = shangJiService.getCarModel(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}

		return resultObj;
	}

	@PostMapping("/getCarInfo")
	public Object getCarInfo(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取车辆参数");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);

		if (getCurrentUserNoVerify(request) != null) {

			map.put("user_id",getCurrentUserNoVerify(request).getId());
		}

		List<Map<String, Object>> result = null;
		JSONObject resultObj = new JSONObject();
		try {
			result = shangJiService.getCarInfo(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}

	@PostMapping("/getClickCarHistory")
	public Object getClickCarHistory(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "获取查询车辆对比历史");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);

		if (getCurrentUserNoVerify(request) != null) {

			map.put("user_id",getCurrentUserNoVerify(request).getId());
		}

		List<Map<String, Object>> result = null;

		JSONObject resultObj = new JSONObject();
		try {
			result = shangJiService.getClickCarHistory(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {

			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");

		}
		return resultObj;
	}


	@PostMapping("/getPublicCarInfo")
	public Object getPublicCarInfo(@RequestBody String str, HttpServletRequest request) throws Exception {
		logBefore(logger, "获取租售列表");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		Map<String, Object> result = null;
		JSONObject resultObj = new JSONObject();
		result = shangJiService.getPublicCarInfo(currentUser, map,device);
		resultObj.put("data", result);
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		return resultObj;
	}

	@PostMapping("/getPublicCarDetail")
	public Object getPublicCarDetail(@RequestBody String str,HttpServletRequest request) throws Exception {
		logBefore(logger, "获取租售信息");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		Map<String, Object> result = null;
		JSONObject resultObj = new JSONObject();
		result = shangJiService.getPublicCarDetail(map,currentUser,device);
		resultObj.put("data", result);
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		return resultObj;
	}

	/**
	 *
	 * 添加租售信息
	 * @param str
	 * @param request
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/addPublicCarDetail")
	public Object addPublicCarDetail(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "添加租售信息");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		User user = getCurrentUserNoVerify(request);
		map.put("create_user", user == null ? "" : user.getId());
		JSONObject resultObj = new JSONObject();
		try {
			if(map.get("id")!=null && !map.get("id").toString().equals("")) {
				int result = shangJiService.updatePublicCarDetail(map,user);
				if(result > 0) {
					Map<String, Object> resultMap = new HashMap<>();
					resultMap.put("id",map.get("id").toString());
					resultMap.put("result",result);
					resultObj.put("data", resultMap);
					resultObj.put("code", Constants.CODE_SUCCESS);
					resultObj.put("message", "修改成功");
				} else {
					resultObj.put("code", Constants.CODE_HANDEL_FAILED);
					resultObj.put("message", "修改失败");
				}

			} else {
				Map<String, Object> result = shangJiService.addPublicCarDetail(user, map);
				resultObj.put("data", result);
				resultObj.put("code", Constants.CODE_SUCCESS);
				resultObj.put("message", "操作成功");
				//推送给求购的
				shangJiService.pushUser(user,map);
			}

		} catch (Exception e) {
			e.printStackTrace();
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}
		return resultObj;
	}

  	@PostMapping("/publishToServerByShangJi")
	public ResponseBean publishServerByShangJi(@RequestBody Map<String, Object> paraMap, HttpServletRequest request) throws MyException {
		User currentUser = getCurrentUser(request);

		Map<String, String> extraParamsMap = new HashMap<>();
		extraParamsMap.put(PushConstants.KEY_PUSH_QIUGOU, paraMap.get("id").toString());

		String s_id = "a892450bd6084f4484a5479e0a9c1b23";
		// be7bf99ac18a42bdb1f534c85497e227 - 山多维克服务商(测试环境)的s_id
		// a892450bd6084f4484a5479e0a9c1b23 - 无锡钻通(正式环境) s_id
		paraMap.put("s_id", s_id); // 推送r_id为7(管理员)的用户列表
		List<Map<String, String>> guanliyuanList = appDao.getGuanliyuanMapList(paraMap);

		AtomicInteger result = new AtomicInteger();
		guanliyuanList.forEach(guanliyuanItem -> {
			String guanliyuanUserId = guanliyuanItem.get("id");

			Map<String, Object> messageMap = new HashMap<>();
			messageMap.put("push_user_id", guanliyuanUserId);
			messageMap.put("title", "求购信息");
			messageMap.put("push_content", "尊敬的客户您好，我们为您优选了一条求购信息("+ paraMap.get("subject").toString() +")，请查看>>>");
			messageMap.put("create_user", currentUser.getId());

			// 推送消息并且保存推送信息
			PushResult pushResultresult = jiGuangPushUtil.publishMessagePush(messageMap, PushConstants.KEY_PUSH_QIUGOU, "", extraParamsMap, UuidUtil.get32UUID());
			// 如果消息推送成功，则把保存消息并把该发布的消息设置为已发送(方便市场人员区别处理)
			result.addAndGet(pushResultresult == null ? 1 : 0);
			if(pushResultresult != null && pushResultresult.statusCode == 0) {
				messageMap.put("id", UuidUtil.get32UUID());
				messageMap.put("user", currentUser.getId());
				messageMap.put("send_type", "21"); // 发送类型-求购信息发送
				messageMap.put("context", messageMap.get("push_content"));
				messageMap.put("extra_params", "{\"push_qiugou\":\""+ paraMap.get("id").toString() +"\"}");
				messageMap.put("receive_user", guanliyuanUserId);
				messageMap.put("s_id", s_id);
				messageMap.put("client","YD");
				messageRecordDao.addMessageRecord(messageMap);

				// 更新是否推送的标识
				shangJiDao.updateZoweBuyinfoDetailForPushFlag(paraMap);
			}
		});
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", result);
	}

	/**
	 * 更改促销状态
	 * @param str
	 * @param request
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/updateBuyinfoPromotion")
	public Object updateBuyinfoPromotion(@RequestBody String str, HttpServletRequest request) throws MyException {
		logBefore(logger, "更改促销状态");

		Map<String, Object> map = JSONObject.parseObject(str, Map.class);
		User user = getCurrentUser(request);
		shangJiService.updateBuyinfoPromotion(user, map);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", true);
	}


	/**
	 * 审核租售信息
	 * @param str
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/checkCarDetail")
	public Object checkCarDetail(@RequestBody String str, HttpServletRequest request) throws Exception {
		logBefore(logger, "审核租售信息");
		String userId = getCurrentUser(request).getId();
		Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
		reqMap.put("update_user", userId);
		boolean status = shangJiService.updateCarDetailExamineFlag(reqMap);
		Map<String, Object> resultObj = new HashMap<>(2);
		resultObj.put("status", status);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultObj);
	}

	/**
	 * 地图展现形式 当前位置，数据按距离升序
	 * @param str
	 * @return
	 * @throws MyException
	 */
	@PostMapping("/lonlatList")
	public Object lonlatList(@RequestBody String str) throws MyException {
		logBefore(logger, "地图展现形式");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		List<Map<String, Object>> result=null;
		JSONObject resultObj = new JSONObject();
		try {
			result = shangJiService.getPublicCarInfoByLonlat(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {
			e.printStackTrace();
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}
		return resultObj;
	}


	@PostMapping(value="/uploadVideo")
	public Object uploadVideo(MultipartFile[] files , HttpServletRequest request){
		/*List<UploadResult> list=new ArrayList<>();
		try {
			for(MultipartFile file:files){
				UploadResult result= UploadFile.uploadVideo(file,"others",request);
				String imgUrl= UploadFile.fetchFrame(result.getFinalFileName());
				if(StringUtils.isNotEmpty(imgUrl)){
					result.setFinalFileName(result.getFinalFileName()+","+imgUrl);
				}
				list.add(result);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}*/
		//返回json
        JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
//		resultObj.put("data", list);
		return resultObj;
	}

	@PostMapping(value="/uploadImg")
	public Object uploadImg(MultipartFile[] files , HttpServletRequest request){
		List<UploadResult> list=new ArrayList<>();

		String uploadPath = "others";
		User currentUser = getCurrentUserNoVerify(request);
		Map<String, Object> map = new HashMap<>();
		map.put("type", request.getParameter("type"));
		try {
			for(MultipartFile file:files){
				list.add(UploadFile.uploadImg(file,"others", currentUser, map));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//返回json
		JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		resultObj.put("data", list);
		return resultObj;
	}

	@PostMapping(value="/uploadFiles")
	public Object uploadFiles(MultipartFile[] files , HttpServletRequest request){

		List<UploadResult> list=new ArrayList<>();

		String uploadPath = "others";
		User currentUser = getCurrentUserNoVerify(request);
		Map<String, Object> map = new HashMap<>();
		map.put("type", request.getParameter("type"));

		try {
			for(MultipartFile file:files){
				list.add(UploadFile.uploadFiles(file,"others", currentUser, map));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//返回json
		JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		resultObj.put("data", list);
		return resultObj;
	}


	@PostMapping(value="/delFile")
	public Object delFile(String path , HttpServletRequest request){
		UploadResult uploadResult=null;
		try {
			String[] imgPath = path.split(",");
			for(int i = 0; i<imgPath.length; i++) {
				uploadResult = UploadFile.delFile(path);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		//返回json
		JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		resultObj.put("data", uploadResult);
		return resultObj;

//		UploadResult uploadResult=null;
//		//返回json
//		JSONObject resultObj = new JSONObject();
//		String[] imgPath = path.split(",");
//		String paths = "";
//		for(int i = 0; i<imgPath.length; i++) {
//			try {
//				uploadResult = UploadFile.delFile(path);
//			} catch (Exception e) {
//				// TODO: handle exception
//				if (paths.equals("")) {
//					paths = paths+path;
//				} else {
//					paths = paths + "," + path;
//				}
//				resultObj.put("code", Constants.CODE_HANDEL_FAILED);
//				resultObj.put("message", "操作失败");
//				resultObj.put("data", new UploadResult(1, "部分地址："+paths+"错误,请重新输入"));
//				return resultObj;
//			}
//		}
//		resultObj.put("code", Constants.CODE_SUCCESS);
//		resultObj.put("message", "操作成功");
//		resultObj.put("data", uploadResult);
//		return resultObj;

	}

    @PostMapping(value="/getProvince")
    public Object province(@RequestBody String str) {
        logBefore(logger, "查询省");
        Map<String, Object> reqMap = JSONObject.parseObject(str,Map.class);
        List<Map<String,Object>> addressList=shangJiService.province(reqMap);
//        if(null!=addressList&&addressList.size()>0){
//            result.put(reqMap.get("number").toString(),addressList);
//        }
        logAfter(logger);
        JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		resultObj.put("data", addressList);
		return resultObj;
    }

    @PostMapping(value="/getCity")
    public Object city(@RequestBody String str) {
        logBefore(logger, "查询市");
        Map<String, Object> result=new HashMap<>();
        Map<String, Object> reqMap = JSONObject.parseObject(str,Map.class);
        List<Map<String,Object>> addressList=shangJiService.city(reqMap);
        if(null!=addressList&&addressList.size()>0){
            result.put(reqMap.get("number").toString(),addressList);
        }
        JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		resultObj.put("data", result);
		return resultObj;
    }

    @PostMapping(value="/getArea")
    public Object area(@RequestBody String str) {
        logBefore(logger, "查询区");
        Map<String, Object> result=new HashMap<>();
        Map<String, Object> reqMap = JSONObject.parseObject(str,Map.class);
        List<Map<String,Object>> addressList=shangJiService.area(reqMap);
        addressList.forEach(item ->{
            item.put("isLeaf",true);
        });
        if(null!=addressList&&addressList.size()>0){
            result.put(reqMap.get("number").toString(),addressList);
        }
        JSONObject resultObj = new JSONObject();
		resultObj.put("code", Constants.CODE_SUCCESS);
		resultObj.put("message", "操作成功");
		resultObj.put("data", result);
		return resultObj;
    }

	//搜索商城列表
	@PostMapping("/getMallList")
	public Object getMallList(@RequestBody String str) throws MyException {
		logBefore(logger, "搜索商城列表");

		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		Map<String, Object> result;
		JSONObject resultObj = new JSONObject();
		try {
			result = shangJiService.getMallList(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}

		return resultObj;
	}

	@PostMapping("/getNewsList")
	public Object getNewsList(@RequestBody String str) throws MyException {
		logBefore(logger, "获取新闻列表");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		JSONObject resultObj = new JSONObject();
		try {
			Map<String, Object> result = shangJiService.getNewsList(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {
			e.printStackTrace();
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}
		return resultObj;
	}

	@PostMapping("/getNewsDetail")
	public Object getNewsDetail(@RequestBody String str) throws MyException {
		logBefore(logger, "获取新闻详情");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		JSONObject resultObj = new JSONObject();
		try {
			Map<String, Object> result = shangJiService.getNewsDetail(map);
			resultObj.put("data", result);
			resultObj.put("code", Constants.CODE_SUCCESS);
			resultObj.put("message", "操作成功");
		} catch (Exception e) {
			e.printStackTrace();
			resultObj.put("code", Constants.CODE_HANDEL_FAILED);
			resultObj.put("message", "操作失败");
		}
		return resultObj;
	}

	/**
	 * 获取新机发布过的机型
	 * @param str
	 * @param request
	 * @return
	 */
	@PostMapping("getModelList")
	public ResponseBean getModelList(@RequestBody String str, HttpServletRequest request){
		logBefore(logger, "获取新机发布过的机型");
		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
		List<Map<String, Object>> modelList = shangJiService.getModelList(map);
		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", modelList);
	}

	/**
	 * 分享获取分数
	 * @param str
	 * @param request
	 * @return
	 */
	@PostMapping("shareBehavior")
	public ResponseBean shareBehavior(@RequestBody String str,HttpServletRequest request){
		logBefore(logger,"分享获取分数");
		Map<String,Object> reqMap = JSONObject.parseObject(str,Map.class);
		User currentUser = getCurrentUserNoVerify(request);
		String device = getDevice(request);
		int result = shangJiService.shareBehavior(reqMap,currentUser,device);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
	}
//	@PostMapping("test")
//	public ResponseBean test(@RequestBody String str, HttpServletRequest request){
//		logBefore(logger, "测试");
//		Map<String, Object> map = JSONObject.parseObject(str,Map.class);
//		shangJiService.insertUserBehavior(map);
//		return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "成功");
//	}
	@PostMapping("getNewMachineList")
	public ResponseBean getNewMachineList(@RequestBody String str,HttpServletRequest request){
		logBefore(logger,"获取新机列表");
		Map<String,Object> reqMap = JSONObject.parseObject(str,Map.class);
		User currentUser = getCurrentUserNoVerify(request);
		Map<String,Object> result = shangJiService.getNewMachineList(reqMap,currentUser);
		return new ResponseBean(Constants.CODE_SUCCESS,"操作成功",result);
}
}
